<template>
  <el-container style="height:100%">
    <!-- 頭部 -->
    <el-header>
      <span style="font-size:30px;m ">後台管理系統</span>
      <el-button
        @click="clearToken()"
        style="float:right; "
      >退出登錄</el-button>
    </el-header>
    <el-container>
      <!-- 左側 -->
      <el-aside width="200px">
        <!-- 側邊欄 -->
        <el-menu
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#438aff"
          :unique-opened="true"
          :router="true"
        >
          <!-- 一級菜單 -->
          <el-submenu
            :index="item.id +' ' "
            v-for="item in meunList"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iconObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 二級菜單 -->
            <el-menu-item
              :index="'/'+subItem.path "
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>

          </el-submenu>

        </el-menu>
      </el-aside>
      <!-- 右側 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
export default {
  data() {
    return {
      meunList: [],
      iconObj: {
        125: "el-icon-user-solid",
        103: "el-icon-s-grid",
        101: "el-icon-s-goods",
        102: "el-icon-s-order",
        145: "el-icon-s-marketing",
      },
    };
  },
  created() {
    this.ddd();
  },
  mounted() {
    // this.ddd()
  },

  methods: {
    clearToken() {
      window.sessionStorage.clear();
      this.$router.push("/login");
      this.$message({
        message: "退出成功",
        type: "success",
      });
    },

    async ddd() {
      const res = await this.$http.get("menus");
      // console.log(res.data);

      if (res.data.meta.status !== 200) {
        this.$message.error(res.data.meta.msg);
      } else {
        this.meunList = res.data.data;
        // console.log(this.meunList);
      }
    },
  },
};
</script>

<style scoped>
.el-header {
  background-color: dimgray;
  color: white;
  padding-top: 10px;
}
.el-aside {
  background-color: aquamarine;
}
.el-main {
  background-color: gainsboro;
}
.el-menu {
  border-right: 0px;
}
</style>
